//
//  NSFileManager+CNBCExtension.m
//  主要针对各钟文件操作，用于记录各种数据(排名、设置等);
//
//  Created by linda on 6/16/11.
//  Copyright 2011 . All rights reserved.
//

#import "NSFileManager+Extension.h"


@implementation NSFileManager(Extension)

+(NSString *)getPathForAlertSetting
{
    NSString *path = [DOCUMENTS_PATH stringByAppendingPathComponent:@"Setting"];
    
    if ( [[self class] createFileAtPath:path] ) {
        return path;
    }
    return nil;
}

+(BOOL)isFileExist:(NSString *)absolutePath
{    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    BOOL isDirectory = YES;
    if ( [fileManager fileExistsAtPath:absolutePath isDirectory:&isDirectory]) {
        return YES;
    }
    return NO;
}

+(BOOL)createFileAtPath:(NSString *)absolutePath
{
   
    if ( [NSFileManager isFileExist:absolutePath] ) {
        return YES;
    }
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    
    NSError *error;
    
    if ( [fileManager createDirectoryAtPath:absolutePath withIntermediateDirectories:YES attributes:nil error:&error] )
    {
        return YES;
    }
    
    return NO;
}
+(BOOL)deleteFileAtPath:(NSString *)absolutePath
{
    if ( ![NSFileManager isFileExist:absolutePath] )
    {
        return YES;
    }
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    
    NSError *error;
    
    if ( [fileManager removeItemAtPath:absolutePath error:&error]) {
        return YES;
    }
    return NO;
}
@end
